angular.module('starter')
    .controller('myinfoCtrl', function($scope, $ionicPopup, IonicClosePopupService, $interval, meilvFac) {
        $scope.initInfo = function() {
                meilvFac.user.userinfoget(
                    function(data) {
                        $scope.personInfo = data.info
                    },
                    function(data) {
                        alert(data.info)
                    }
                )
            }
            /*昵称*/
        $scope.showPopup = function() {
            $scope.personInfo.changename=$scope.personInfo.username;
            var myPopup = $ionicPopup.show({
                template: '<style>.popup-head{display:none;color:#616161!important;}.popup-body{padding-bottom:0!important;}.popup-container .popup{width:310px;}.popup{position:relative;background:#fff!important;border-radius:10px!important;padding:10px;}.button{border-radius:25px!important;background:#7ED321!important;}</style><div><h1 style="text-align:left;font-size:16px;line-height:30px;" class="grayC2">昵称</h1><div style="margin:10px auto;text-align:center"><input ng-model="personInfo.changename" type="text" placeholder="请输入昵称" style="border-radius:20px;height:45px;box-shadow:1px 1px 3px #999 inset;padding:0 10px;"></div></div><div style="background:#fff;border:1px solid #7ed321;border-radius:50%;position:absolute;right:-10px;top:-10px;font-size:20px;width:28px;height:28px;text-align:center;line-height:28px;"><i class="iconfont icon-cancel" ng-click="popupClose()" style="color:#7ED321;"></i></div>',
                title: null,
                subTitle: null,
                scope: $scope,
                buttons: [{
                    text: '<span>保存</span>',
                    type: 'button-positive',
                    onTap: function(e) {
                        meilvFac.user.userinfoedit(
                            {username:$scope.personInfo.changename},
                            function(data) {
                                $scope.initInfo();
                            },
                            function(data) {
                                alert(data.info)
                            }
                        )
                    }
                }]
            })
            IonicClosePopupService.register(myPopup);
            $scope.popupClose = function() {
                myPopup.close();
            }
        }

        /*真实姓名*/
        $scope.showPopupName = function() {
            $scope.personInfo.changerealname=$scope.personInfo.realname;
            var myPopup = $ionicPopup.show({
                template: '<style>.popup-head{display:none;color:#616161!important;}.popup-body{padding-bottom:0!important;}.popup-container .popup{width:310px;}.popup{position:relative;background:#fff!important;border-radius:10px!important;padding:10px;}.button{border-radius:25px!important;background:#7ED321!important;}</style><div><h1 style="text-align:left;font-size:16px;line-height:30px;" class="grayC2">真实姓名</h1><div style="margin:10px auto;text-align:center"><input ng-model="personInfo.changerealname" type="text" placeholder="请输入真实姓名" style="border-radius:20px;height:45px;box-shadow:1px 1px 3px #999 inset;padding:0 10px;"></div></div><div style="background:#fff;border:1px solid #7ed321;border-radius:50%;position:absolute;right:-10px;top:-10px;font-size:20px;width:28px;height:28px;text-align:center;line-height:28px;"><i class="iconfont icon-cancel" ng-click="popupClose()" style="color:#7ED321;"></i></div>',
                title: null,
                subTitle: null,
                scope: $scope,
                buttons: [{
                    text: '<span>保存</span>',
                    type: 'button-positive',
                    onTap: function(e) {
                        meilvFac.user.userinfoedit(
                            {realname:$scope.personInfo.changerealname},
                            function(data) {
                                console.log(data)
                                $scope.initInfo();
                            },
                            function(data) {
                                alert(data.info);
                            }
                        )
                    }
                }]
            })
            IonicClosePopupService.register(myPopup);
            $scope.popupClose = function() {
                myPopup.close();
            }
        }

        /*手机号*/
        $scope.showPopupPhone = function() {
            $scope.personInfo.phone=$scope.personInfo.mobile;
            var myPopup = $ionicPopup.show({
                    template: '<style>.popup-head{display:none;color:#616161!important;}.popup-body{padding-bottom:0!important;}.popup-container .popup{width:310px;}.popup{position:relative;background:#fff!important;border-radius:10px!important;padding:10px;}.button{border-radius:25px!important;background:#7ED321!important;}</style><div><h1 style="text-align:left;font-size:16px;line-height:30px;" class="grayC2">手机号码</h1><div style="margin:10px auto;text-align:center"><input type="number" placeholder="请输入手机号码" ng-model="personInfo.phone" style="border-radius:20px;height:45px;box-shadow:1px 1px 3px #999 inset;padding:0 10px;"></div></div><div style="background:#fff;border:1px solid #7ed321;border-radius:50%;position:absolute;right:-10px;top:-10px;font-size:20px;width:28px;height:28px;text-align:center;line-height:28px;"><i class="iconfont icon-cancel" ng-click="popupClose()" style="color:#7ED321;"></i></div>',
                    title: null,
                    subTitle: null,
                    scope: $scope,
                    buttons: [{
                        text: '<span>保存<span>',
                        type: 'button-positive',
                        onTap: function(e) {
                        meilvFac.user.userinfoedit(
                            {mobile:$scope.personInfo.phone},
                            function(data) {
                                $scope.initInfo();
                            },
                            function(data) {
                                console.log(data);
                            }
                        )
                        }
                    }]
                })
                IonicClosePopupService.register(myPopup);
            $scope.popupClose = function() {
                myPopup.close();

            }
        }
    })
